package com.zx.BookSeaReader.greendao.gen;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.zx.BookSeaReader.greendao.entity.BookListCollect;
import com.zx.BookSeaReader.greendao.entity.BookListSubscribe;

import com.zx.BookSeaReader.greendao.entity.BookListBean;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "BOOK_LIST_BEAN".
*/
public class BookListBeanDao extends AbstractDao<BookListBean, Long> {

    public static final String TABLENAME = "BOOK_LIST_BEAN";

    /**
     * Properties of entity BookListBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property ListId = new Property(0, Long.class, "listId", true, "_id");
        public final static Property Title = new Property(1, String.class, "title", false, "TITLE");
        public final static Property Username = new Property(2, String.class, "username", false, "USERNAME");
        public final static Property Desc = new Property(3, String.class, "desc", false, "DESC");
        public final static Property CollectorCount = new Property(4, int.class, "collectorCount", false, "COLLECTOR_COUNT");
        public final static Property Cover = new Property(5, String.class, "cover", false, "COVER");
        public final static Property BookCount = new Property(6, int.class, "bookCount", false, "BOOK_COUNT");
        public final static Property Bookindex = new Property(7, int.class, "bookindex", false, "BOOKINDEX");
        public final static Property IsRelease = new Property(8, boolean.class, "isRelease", false, "IS_RELEASE");
        public final static Property CreateTime = new Property(9, String.class, "createTime", false, "CREATE_TIME");
    }

    private DaoSession daoSession;

    private Query<BookListBean> book_BookListsQuery;
    private Query<BookListBean> userBean_BookListBeansQuery;

    public BookListBeanDao(DaoConfig config) {
        super(config);
    }
    
    public BookListBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
        this.daoSession = daoSession;
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"BOOK_LIST_BEAN\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: listId
                "\"TITLE\" TEXT," + // 1: title
                "\"USERNAME\" TEXT," + // 2: username
                "\"DESC\" TEXT," + // 3: desc
                "\"COLLECTOR_COUNT\" INTEGER NOT NULL ," + // 4: collectorCount
                "\"COVER\" TEXT," + // 5: cover
                "\"BOOK_COUNT\" INTEGER NOT NULL ," + // 6: bookCount
                "\"BOOKINDEX\" INTEGER NOT NULL ," + // 7: bookindex
                "\"IS_RELEASE\" INTEGER NOT NULL ," + // 8: isRelease
                "\"CREATE_TIME\" TEXT);"); // 9: createTime
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"BOOK_LIST_BEAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, BookListBean entity) {
        stmt.clearBindings();
 
        Long listId = entity.getListId();
        if (listId != null) {
            stmt.bindLong(1, listId);
        }
 
        String title = entity.getTitle();
        if (title != null) {
            stmt.bindString(2, title);
        }
 
        String username = entity.getUsername();
        if (username != null) {
            stmt.bindString(3, username);
        }
 
        String desc = entity.getDesc();
        if (desc != null) {
            stmt.bindString(4, desc);
        }
        stmt.bindLong(5, entity.getCollectorCount());
 
        String cover = entity.getCover();
        if (cover != null) {
            stmt.bindString(6, cover);
        }
        stmt.bindLong(7, entity.getBookCount());
        stmt.bindLong(8, entity.getBookindex());
        stmt.bindLong(9, entity.getIsRelease() ? 1L: 0L);
 
        String createTime = entity.getCreateTime();
        if (createTime != null) {
            stmt.bindString(10, createTime);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, BookListBean entity) {
        stmt.clearBindings();
 
        Long listId = entity.getListId();
        if (listId != null) {
            stmt.bindLong(1, listId);
        }
 
        String title = entity.getTitle();
        if (title != null) {
            stmt.bindString(2, title);
        }
 
        String username = entity.getUsername();
        if (username != null) {
            stmt.bindString(3, username);
        }
 
        String desc = entity.getDesc();
        if (desc != null) {
            stmt.bindString(4, desc);
        }
        stmt.bindLong(5, entity.getCollectorCount());
 
        String cover = entity.getCover();
        if (cover != null) {
            stmt.bindString(6, cover);
        }
        stmt.bindLong(7, entity.getBookCount());
        stmt.bindLong(8, entity.getBookindex());
        stmt.bindLong(9, entity.getIsRelease() ? 1L: 0L);
 
        String createTime = entity.getCreateTime();
        if (createTime != null) {
            stmt.bindString(10, createTime);
        }
    }

    @Override
    protected final void attachEntity(BookListBean entity) {
        super.attachEntity(entity);
        entity.__setDaoSession(daoSession);
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public BookListBean readEntity(Cursor cursor, int offset) {
        BookListBean entity = new BookListBean( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // listId
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // title
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // username
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // desc
            cursor.getInt(offset + 4), // collectorCount
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // cover
            cursor.getInt(offset + 6), // bookCount
            cursor.getInt(offset + 7), // bookindex
            cursor.getShort(offset + 8) != 0, // isRelease
            cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9) // createTime
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, BookListBean entity, int offset) {
        entity.setListId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setTitle(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setUsername(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setDesc(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setCollectorCount(cursor.getInt(offset + 4));
        entity.setCover(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setBookCount(cursor.getInt(offset + 6));
        entity.setBookindex(cursor.getInt(offset + 7));
        entity.setIsRelease(cursor.getShort(offset + 8) != 0);
        entity.setCreateTime(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(BookListBean entity, long rowId) {
        entity.setListId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(BookListBean entity) {
        if(entity != null) {
            return entity.getListId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(BookListBean entity) {
        return entity.getListId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "bookLists" to-many relationship of Book. */
    public List<BookListBean> _queryBook_BookLists(String bookid) {
        synchronized (this) {
            if (book_BookListsQuery == null) {
                QueryBuilder<BookListBean> queryBuilder = queryBuilder();
                queryBuilder.join(BookListCollect.class, BookListCollectDao.Properties.BookListid)
                    .where(BookListCollectDao.Properties.Bookid.eq(bookid));
                book_BookListsQuery = queryBuilder.build();
            }
        }
        Query<BookListBean> query = book_BookListsQuery.forCurrentThread();
        query.setParameter(0, bookid);
        return query.list();
    }

    /** Internal query to resolve the "bookListBeans" to-many relationship of UserBean. */
    public List<BookListBean> _queryUserBean_BookListBeans(Long userid) {
        synchronized (this) {
            if (userBean_BookListBeansQuery == null) {
                QueryBuilder<BookListBean> queryBuilder = queryBuilder();
                queryBuilder.join(BookListSubscribe.class, BookListSubscribeDao.Properties.BookListid)
                    .where(BookListSubscribeDao.Properties.Userid.eq(userid));
                userBean_BookListBeansQuery = queryBuilder.build();
            }
        }
        Query<BookListBean> query = userBean_BookListBeansQuery.forCurrentThread();
        query.setParameter(0, userid);
        return query.list();
    }

}
